import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 模块级别(依据级别值顺序优先启动) */
export enum PackLevelEnum {
  /** 核心级别
   * 表示系统的核心模块
   */
  Core = 100,
  /** 框架级别
   * 表示涉及第三方组件的基础模块
   */
  Framework = 200,
  /** 应用级别
   * 表示涉及应用数据的基础模块
   */
  Application = 300,
  /** 业务级别
   * 表示涉及业务数据的基础模块
   */
  Business = 400,
  /** 模块级别
   * 表示涉及具体业务的单元模块
   */
  Module = 500,
}

/**  模块级别实体 */
export class PackLevelEntity {
  /** 访问类型 */
  PackLevel: PackLevelEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(packLevel: PackLevelEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.PackLevel = packLevel;
    this.Color = color;
    switch (packLevel) {
      case PackLevelEnum.Core:
        // this.Display = '核心级别';
        this.Display = t('enum.packLevel.core');
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
      case PackLevelEnum.Framework:
        // this.Display = '框架级别';
        this.Display = t('enum.packLevel.framework');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case PackLevelEnum.Application:
        // this.Display = '应用级别';
        this.Display = t('enum.packLevel.application');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case PackLevelEnum.Business:
        // this.Display = '业务级别';
        this.Display = t('enum.packLevel.business');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case PackLevelEnum.Module:
        // this.Display = '模块级别';
        this.Display = t('enum.packLevel.module');
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
    }
  }
}

//#region 获取模块级别枚举架构
/**
 * 获取模块级别枚举架构
 */
export function getPackLevelEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: PackLevelEntity[] = [
    new PackLevelEntity(PackLevelEnum.Core),
    new PackLevelEntity(PackLevelEnum.Framework),
    new PackLevelEntity(PackLevelEnum.Application),
    new PackLevelEntity(PackLevelEnum.Business),
    new PackLevelEntity(PackLevelEnum.Module),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.PackLevel as number,
      label: item.Display,
      value: item.PackLevel as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
